﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <script type="text/javascript" src="lib/PIE_IE678.js"></script>
    <![endif]-->
    <link href="static/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="static/h-ui.admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
    <link href="static/h-ui.admin/css/style.css" rel="stylesheet" type="text/css" />
    <link href="lib/Hui-iconfont/1.0.7/iconfont.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>后台登录 - 房产估价系统</title>
    <meta name="keywords" content="房产估价系统" />
    <meta name=" description" content="房产估价系统">
</head>
<body>
    <div class="header"></div>
    <div class="loginWraper">
        <div id="loginform" class="loginBox">
            <form class="form form-horizontal">
                <div class="row cl">
                    <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60d;</i></label>
                    <div class="formControls col-xs-8">
                        <input id="T_Account" name="T_Account" type="text" placeholder="账户" class="input-text size-L">
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60e;</i></label>
                    <div class="formControls col-xs-8">
                        <input id="T_Password" name="T_Password" type="password" placeholder="密码" class="input-text size-L">
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe6c5;</i></label>
                    <div class="formControls col-xs-8">
                        <input id="T_Code" name="T_Code" class="input-text size-L" type="text" placeholder="验证码" style="width:150px;">
                        <img src="static/GetImg.jpg" id="GetImg"> <a id="kanbuq" href="javascript:;">看不清，换一张</a>
                    </div>
                </div>
                <div class="row cl">
                    <div class="formControls col-xs-8 col-xs-offset-3">
                        <label for="online">
                            <input type="checkbox" name="online" id="online" />
                            使我保持登录状态
                        </label>
                    </div>
                </div>
                <div class="row cl">
                    <div class="formControls col-xs-8 col-xs-offset-3">
                        <input id="btnLogin" type="button" class="btn btn-success btn-loading radius size-L" value="&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;">
                        <input type="reset" class="btn btn-default btn-loading radius size-L" value="&nbsp;取&nbsp;&nbsp;&nbsp;&nbsp;消&nbsp;">
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="footer">Copyright 北京中资房地产土地评估有限公司 by 房产估价系统1.0</div>
    <script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="static/h-ui/js/H-ui.js"></script>
    <script type="text/javascript" src="lib/layer/1.9.3/layer.js"></script>
    <script type="text/javascript">
        var ApiUrl = "http://localhost:6260/";
        if (!jQuery.support.cors) {
            jQuery.support.cors = true;
        }
        /*验证码*/
        var Logincode = "";
        function ShowCodeImg() {
            var url = ApiUrl + "api/Login/GetCodeImg" + "?t=" + (new Date()).getTime();
            $.ajax({
                type: "get",
                url: url,
                success: function (data, status) {
                    if (status == "success") {
                        Logincode = data.code;
                        $("#GetImg").attr("src", "data:image/jpg;base64," + data.imgByte);

                        //var reader = new FileReader();
                        //reader.onload = function () {
                        //    $("#GetImg").attr("src", this.result);
                        //};
                        //reader.readAsArrayBuffer(data.imgByte);
                    }
                },
                error: function (e) {
                    layer.msg('验证码刷新失败!', { icon: 2, time: 1000 });
                },
                complete: function () {
                }
            })
            //$.ajax({
            //    type: "get",
            //    url: url,
            //    complete: function (xhr, status) {
            //        //Logincode = xhr.getResponseHeader("code");
            //        Logincode = xhr.statusText;
            //        $("#GetImg").attr("src", "data:image/jpg;base64," + xhr.responseText);

            //        var reader = new FileReader();
            //        reader.onload = function () {

            //        };
            //        reader.readAsArrayBuffer();
            //    },
            //})
        }
        $(function () {
            /*验证码*/
            ShowCodeImg()
            $("#kanbuq").click(function () {
                ShowCodeImg();
            });
            /*登录*/
            $("#btnLogin").click(function () {
                if ($("#T_Account").val() == "" || $("#T_Password").val() == "") {
                    layer.msg('账号和密码不能为空!', { icon: 4, time: 1000 });
                } else {
                    //alert(Logincode);
                    if ($("#T_Code").val().toLowerCase() != Logincode) {
                        layer.msg('验证码输入错误!', { icon: 2, time: 1000 });
                        ShowCodeImg()
                        $("#T_Code").val("");
                    } else {
                        var par = $(".form-horizontal").serialize();
                        Denglu(par);
                    }
                }
            });

            /*选择记住密码自动登录*/
            $("#online").click(function () {
                var storage = window.localStorage;
                if (this.checked) {
                    storage.setItem("online", "ok");
                } else {
                    storage.removeItem("online");
                }
            })

            /*是否自动登录*/
            var storage = window.localStorage;
            var online = storage.getItem('online');
            var account = storage.getItem('account');
            var pwd = storage.getItem('pwd');
            if (online == null || online == "" || online == undefined ||
               account == null || account == "" || account == undefined ||
               pwd == null || pwd == "" || pwd == undefined) {
                //location.href = "login.html";
            }
            else {
                if (online == "ok") {
                    var par = {
                        T_Account: account,
                        T_Password: pwd
                    }
                    Denglu(par);
                }
            }
        })

        //登录ajax
        function Denglu(par) {
            $.ajax({
                type: "post",
                url: ApiUrl + "api/Login/GetLogin",
                data: par,
                success: function (data, status) {
                    if (status == "success") {
                        if (data.state) {
                            var storage = window.localStorage;
                            storage.setItem('token', data.token);
                            storage.setItem("userid", data.userid);
                            storage.setItem("account", data.account);
                            storage.setItem("name", data.name);
                            storage.setItem("pwd", data.pwd);
                            storage.setItem("dept", data.dept);
                            storage.setItem("role", data.role);
                            location.href = "Index.html";
                            layer.msg('登录成功!', { icon: 1, time: 1000 });
                        } else {
                            layer.msg(data.message, { icon: 2, time: 1000 });
                            ShowCodeImg();
                            $("#T_Code").val("");
                        }
                    }
                },
                error: function (e) {
                    layer.msg('服务器链接超时!', { icon: 2, time: 1000 });
                },
                complete: function () {
                }
            })
        }
    </script>
</body>
</html>